package com.bluesky.objectworld.primitive;

import com.bluesky.objectworld.ObjectImpl;
import com.bluesky.objectworld.VirtualMachine;
import com.bluesky.objectworld._Object;

public class _Integer extends ObjectImpl {
	public int value;

	@Override
	public _Object processMessage(String name, _Object[] parameters) {	
		if ("self".equals(name))
			return this;
		
		_Integer i = (_Integer) parameters[0];
			
		if ("add".equals(name))
			return add(i);
		else if ("sub".equals(name))
			return sub(i);
		else if ("mul".equals(name))
			return mul(i);
		else if ("div".equals(name))
			return div(i);
		
		return null;

	};

	_Integer add(_Integer i) {
		int c = this.value + i.value;

		_Integer intEgg = (_Integer) VirtualMachine.getInstance().world.create(
				PrimitiveType.Integer, String.valueOf(c));

		return intEgg;
	}

	_Integer sub(_Integer i) {
		int c = this.value + i.value;

		_Integer intEgg = (_Integer) VirtualMachine.getInstance().world.create(
				PrimitiveType.Integer, String.valueOf(c));

		return intEgg;
	}

	_Integer mul(_Integer i) {
		int c = this.value * i.value;

		_Integer intEgg = (_Integer) VirtualMachine.getInstance().world.create(
				PrimitiveType.Integer, String.valueOf(c));

		return intEgg;
	}

	_Integer div(_Integer i) {
		int c = this.value / i.value;

		_Integer intEgg = (_Integer) VirtualMachine.getInstance().world.create(
				PrimitiveType.Integer, String.valueOf(c));

		return intEgg;
	}

	@Override
	public String toString() {

		return super.toString() + String.format("|value:%d", value);
	}

}
